package logic

import (
	"context"

	"go-zero-mall/app/product/cmd/rpc/internal/svc"
	"go-zero-mall/app/product/cmd/rpc/pb"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type PmsMemberPriceInfoListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPmsMemberPriceInfoListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PmsMemberPriceInfoListLogic {
	return &PmsMemberPriceInfoListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PmsMemberPriceInfoListLogic) PmsMemberPriceInfoList(in *pb.PmsMemberPriceInfoListReq) (*pb.PmsMemberPriceInfoListResp, error) {
	countBuilder := l.svcCtx.PmsMemberPriceModel.CountBuilder("*")
	rowBuilder := l.svcCtx.PmsMemberPriceModel.RowBuilder()
	list, err := l.svcCtx.PmsMemberPriceModel.FindByPageParam(l.ctx, rowBuilder, in.PageNum, in.PageSize)
	if err != nil {
		return nil, err
	}
	total, err := l.svcCtx.PmsMemberPriceModel.FindCount(l.ctx, countBuilder)
	if err != nil {
		return nil, err
	}
	var d []*pb.PmsMemberPriceInfo
	copier.Copy(&d, list)
	return &pb.PmsMemberPriceInfoListResp{Total: total, List: d}, nil
}
